package com.cj.http;

import com.cj.models.BookModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;


@RestController
@RequestMapping(path = "/books")
public class BooksGet {

    @GetMapping("")
    public List<BookModel> books(HttpServletRequest request){
        List<BookModel> bookModels = new ArrayList<>();
        bookModels.add(new BookModel(101,"java图书"));
        bookModels.add(new BookModel(102,"PHP图书馆"));
        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()){
            String headName = headers.nextElement();
            System.out.println(headName);
            System.out.println(request.getHeader(headName));
        }
        return bookModels;
    }

}
